package com.mydemo.controller;

import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import static org.springframework.ai.chat.memory.ChatMemory.CONVERSATION_ID;

@RestController
public class RAG4OpsController {

    @Resource(name="qwenChatClient")
    private ChatClient qwenClient;

    @GetMapping(value = "/persistent2", produces = "text/event-stream;charset=UTF-8")
    public Flux<String> chat2(String msg, String userId){
        //消费形的 advisor
        return qwenClient.prompt(msg)
                .advisors(advisorSpec ->
                        advisorSpec.param(CONVERSATION_ID,userId))
                .stream().content() ;
    }
}
